@model IEnumerable<EIMS.Models.Supplier>

@{
    ViewData["Title"] = "供应商管理";
}

<div class="container-fluid">
    <h1 class="mt-4">供应商管理</h1>
    <ol class="breadcrumb mb-4">
        <li class="breadcrumb-item"><a asp-controller="Home" asp-action="Index">首页</a></li>
        <li class="breadcrumb-item active">供应商管理</li>
    </ol>

    @if (TempData["SuccessMessage"] != null)
    {
        <div class="alert alert-success alert-dismissible fade show" role="alert">
            @TempData["SuccessMessage"]
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
    }

    <div class="card mb-4">
        <div class="card-header">
            <div class="d-flex justify-content-between align-items-center">
                <div>
                    <i class="fas fa-table me-1"></i>
                    供应商列表
                </div>
                @if (User.IsInRole("Administrator") || User.IsInRole("Manager"))
                {
                    <a asp-action="Create" class="btn btn-primary">
                        <i class="fas fa-plus"></i> 新增供应商
                    </a>
                }
            </div>
        </div>
        <div class="card-body">
            <form asp-action="Index" method="get" class="mb-3">
                <div class="row g-3 align-items-center">
                    <div class="col-auto">
                        <input type="text" name="searchString" value="@ViewBag.SearchString" class="form-control" placeholder="搜索..." />
                    </div>
                    <div class="col-auto">
                        <select name="type" class="form-select" asp-items="ViewBag.TypeList">
                            <option value="">-- 全部类型 --</option>
                        </select>
                    </div>
                    <div class="col-auto">
                        <select name="status" class="form-select" asp-items="ViewBag.StatusList">
                            <option value="">-- 全部状态 --</option>
                        </select>
                    </div>
                    <div class="col-auto">
                        <button type="submit" class="btn btn-primary">
                            <i class="fas fa-search"></i> 搜索
                        </button>
                        <a asp-action="Index" class="btn btn-outline-secondary">
                            <i class="fas fa-redo"></i> 重置
                        </a>
                    </div>
                </div>
            </form>

            <div class="table-responsive">
                <table id="suppliersTable" class="table table-bordered table-hover">
                    <thead>
                        <tr>
                            <th>@Html.DisplayNameFor(model => model.SupplierNumber)</th>
                            <th>@Html.DisplayNameFor(model => model.Name)</th>
                            <th>@Html.DisplayNameFor(model => model.Type)</th>
                            <th>@Html.DisplayNameFor(model => model.ContactPerson)</th>
                            <th>@Html.DisplayNameFor(model => model.PhoneNumber)</th>
                            <th>@Html.DisplayNameFor(model => model.Email)</th>
                            <th>@Html.DisplayNameFor(model => model.Status)</th>
                            <th class="text-center">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                    @foreach (var item in Model) {
                        <tr>
                            <td>@Html.DisplayFor(modelItem => item.SupplierNumber)</td>
                            <td>@Html.DisplayFor(modelItem => item.Name)</td>
                            <td>@Html.DisplayFor(modelItem => item.Type)</td>
                            <td>@Html.DisplayFor(modelItem => item.ContactPerson)</td>
                            <td>@Html.DisplayFor(modelItem => item.PhoneNumber)</td>
                            <td>@Html.DisplayFor(modelItem => item.Email)</td>
                            <td>
                                <span class="badge bg-@(item.Status == EIMS.Models.Enums.SupplierStatus.Active ? "success" : 
                                                    item.Status == EIMS.Models.Enums.SupplierStatus.Suspended ? "warning" : "danger")">
                                    @Html.DisplayFor(modelItem => item.Status)
                                </span>
                            </td>
                            <td class="text-center">
                                <div class="btn-group">
                                    <a asp-action="Details" asp-route-id="@item.Id" class="btn btn-sm btn-info">
                                        <i class="fas fa-info-circle"></i>
                                    </a>
                                    @if (User.IsInRole("Administrator") || User.IsInRole("Manager"))
                                    {
                                        <a asp-action="Edit" asp-route-id="@item.Id" class="btn btn-sm btn-primary">
                                            <i class="fas fa-edit"></i>
                                        </a>
                                    }
                                    @if (User.IsInRole("Administrator"))
                                    {
                                        <a asp-action="Delete" asp-route-id="@item.Id" class="btn btn-sm btn-danger">
                                            <i class="fas fa-trash"></i>
                                        </a>
                                    }
                                </div>
                            </td>
                        </tr>
                    }
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

@section Scripts {
    <script>
        $(document).ready(function () {
            $('#suppliersTable').DataTable({
                responsive: true,
                language: {
                    "url": "//cdn.datatables.net/plug-ins/1.10.25/i18n/Chinese.json"
                }
            });
        });
    </script>
} 